import Vue from 'vue'
import VueJsonp from 'vue-jsonp'
Vue.use(VueJsonp);

const URLS={
    multiget:'https://mce.mogucdn.com/jsonp/multiget/3',
    mogujie:'https://list.mogujie.com/search',
    mogucdn: 'https://mce.mogucdn.com/jsonp/get/3',
    mogujieRight:'https://list.mogujie.com/search',
    component:'https://rate.mogujie.com/h5/rate/jsonp/x6.rate.ratelist/v1',
    hotword:'https://list.mogujie.com/module/mget'
}



function loadForHomeData(params = {}) {

    return Vue.jsonp(URLS.multiget, params)
        .then(({ success, data }) => {
            if(success){
                return data;
            }
            return Promise.reject({
                message:"请求失败"
            })
        });
}
function loadmogujieData(params = {}) {

    return Vue.jsonp(URLS.mogujie, params)
        .then(({ success, result }) => {
            if(success){
                return result;
            }
            return Promise.reject({
                message:"请求失败"
            })
        });
}
function loadMogucdnData(params = {}) {

    return Vue.jsonp(URLS.mogucdn, params)
        .then(({ success, data }) => {
            if(success){
                return data;
            }
            return Promise.reject({
                message:"请求失败"
            })
        });
}

function loadComponent(params = {}) {

    return Vue.jsonp(URLS.component, params)
        .then(({ success, data }) => {
            if(success){
                return data;
            
            }
            return Promise.reject({
                message:"请求失败"
            })
        });
}

function loadHotWord(params = {}){
    return Vue.jsonp(URLS.hotword, params)
        .then(({ success, data }) => {
            if(success){
                return data;
            }
            return Promise.reject({
                message:"请求失败"
            })
        });
}



let functionList = {
    loadForHomeData,
    loadmogujieData,
    loadMogucdnData,
    loadComponent,
    loadHotWord
    // loadForTypeData
}

export default {

    install(Vue) {
        Vue.prototype.$api = functionList;

    },
    ...functionList
}